//package com.pp.tourism.gateway.service;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.nacos.api.NacosFactory;
//import com.alibaba.nacos.api.config.ConfigService;
//import com.alibaba.nacos.api.config.listener.Listener;
//import com.alibaba.nacos.api.exception.NacosException;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.route.RouteDefinition;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.Executor;
//
//@Slf4j
//@Component
//public class DynamicRouteServiceImplByNacos {
//
//    @Autowired
//    private DynamicRouteServiceImpl dynamicRouteService;
//
//    public DynamicRouteServiceImplByNacos(){
//        dynamicRouteByNacosListener("tourism-gateway","Tourism");
//     }
//
//
//    public void dynamicRouteByNacosListener(String dataId,String group){
//        try{
//            ConfigService configService = NacosFactory.createConfigService("127.0.0.1:8848");
//            String content = configService.getConfig(dataId, group, 5000);
//            log.info(content);
//            configService.addListener(dataId, group, new Listener()  {
//                @Override
//                public void receiveConfigInfo(String configInfo) {
//                    RouteDefinition definition= JSON.parseObject(configInfo,RouteDefinition.class);
//                    dynamicRouteService.updateRoute(definition);
//                }
//                @Override
//                public Executor getExecutor() {
//                    return null;
//                }
//            });
//        }catch (NacosException e){
//            e.printStackTrace();
//        }
//    }
//}
